﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using DirectorWeb.Models;

// For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860

namespace DirectorWeb.Controllers
{
    public class DirectorPropertiesController : Controller
    {
        private DirectorPropertiesViewModel model = new DirectorPropertiesViewModel();
        // GET: /DirectorProperties/

        public ViewResult Index(string servicesID)
        {
            SetModelAndViewData(servicesID);
            return View(model);
        }

        private void SetModelAndViewData(string servicesID)
        {
            ViewBag.Services = model.Services;

            if (servicesID != null)
            {
                model.SelectedService = servicesID;
                model.GetProperties();
            }
        }

        public ViewResult SetProperty(string endpoint, int propertyId, string propertyValue)
        {
            model.SelectedService = endpoint;
            model.SetProperty(propertyId, propertyValue);
            SetModelAndViewData(endpoint);
            return View("Index", model);
        }
    }
}
